package org.infodavid.common.notifier.impl;

import java.util.HashSet;
import java.util.Set;

import org.infodavid.common.notifier.IAntiSpamOptions;
import org.infodavid.common.notifier.INotifierCommand;
import org.infodavid.common.scheduler.impl.commands.SchedulerCommandImpl;

/**
 * The Class AbstractNotifierCommand.
 */
public abstract class AbstractNotifierCommand extends SchedulerCommandImpl implements INotifierCommand {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 4927128465160123396L;

	/** The anti-spam options. */
	private IAntiSpamOptions asOptions = null;

	/** The from. */
	private String from = null;

	/** The immediate. */
	private boolean immediate = false;

	/** The command identifier. */
	private String key = null;

	/** The subject. */
	private String subject = null;

	/** The to. */
	private final Set<String> to = new HashSet<String>();

	/**
	 * Instantiates a new abstract notifier command.
	 */
	public AbstractNotifierCommand() {
		super();

		asOptions = new DefaultAntiSpamOptions();
	}

	/**
	 * Instantiates a new abstract notifier command.
	 * @param options the options
	 */
	public AbstractNotifierCommand(final IAntiSpamOptions options) {
		super();

		asOptions = options;
	}

	/*
	 * Gets the anti spam options.
	 * @see org.infodavid.common.notifier.INotifierCommand#getAntiSpamOptions()
	 */
	public IAntiSpamOptions getAntiSpamOptions() {
		return asOptions;
	}

	/*
	 * Gets the from.
	 * @see org.infodavid.common.notifier.INotifierCommand#getFrom()
	 */
	public String getFrom() {
		return from;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.notifier.INotifierCommand#getKey()
	 */
	public String getKey() {
		return key;
	}

	/*
	 * Gets the subject.
	 * @see org.infodavid.common.notifier.INotifierCommand#getSubject()
	 */
	public String getSubject() {
		return subject;
	}

	/*
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.notifier.ITextCommand#getTo()
	 */
	public Set<String> getTo() {
		return to;
	}

	/*
	 * Checks if is immediate.
	 * @see org.infodavid.common.notifier.INotifierCommand#isImmediate()
	 */
	public boolean isImmediate() {
		return immediate;
	}

	/*
	 * Sets the from.
	 * @see org.infodavid.common.notifier.INotifierCommand#setFrom(java.lang.String)
	 */
	public void setFrom(final String value) {
		from = value;
	}

	/*
	 * Sets the immediate.
	 * @see org.infodavid.common.notifier.INotifierCommand#setImmediate(boolean)
	 */
	public void setImmediate(final boolean flag) {
		immediate = flag;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.notifier.INotifierCommand#setKey(java.lang.String)
	 */
	public void setKey(final String value) {
		key = value;
	}

	/*
	 * Sets the subject.
	 * @see org.infodavid.common.notifier.INotifierCommand#setSubject(java.lang.String)
	 */
	public void setSubject(final String value) {
		subject = value;
	}

	/*
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.notifier.ITextCommand#setTo(java.lang.String[])
	 */
	public void setTo(final String... values) {
		to.clear();

		if (!(values == null || values.length == 0)) {
			for (final String item : values) {
				to.add(item);
			}
		}
	}

	/*
	 * See super class or interface. (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		final StringBuilder builder = new StringBuilder();

		builder.append(super.toString());
		builder.append("AbstractNotifierCommand [asOptions=");
		builder.append(asOptions);
		builder.append(", key=");
		builder.append(key);
		builder.append(", from=");
		builder.append(from);
		builder.append(", to=");
		builder.append(to);
		builder.append(", subject=");
		builder.append(subject);
		builder.append(", immediate=");
		builder.append(immediate);
		builder.append("]");

		return builder.toString();
	}
}
